// 导入数据库操作模块
const db = require('../db/index')
const https = require('https');

//  登录接口处理函数
exports.login = (req,res) => {
    // console.log(req.body.code);
    //请求获取openid
    let url = "https://api.weixin.qq.com/sns/jscode2session?appid=wxa89ea9e00bbbbe7b&secret=f896b80b1249b70bef6b2d2849ea991e&js_code='+req.body.code+'&grant_type=authorization_code";
    let openid,sessionKey;
    let https = require("https");
    https.get(url, (res) => {
        res.on('data', (d) => {
            console.log('返回的信息: ', JSON.parse(d));
            openid = JSON.parse(d).openid;//得到openid
            sessionKey = JSON.parse(d).session_key;//得到session_key
        }).on('error', (e) => {
            console.error(e);
        });
    });

}

